package ui;

import java.awt.BorderLayout;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * This panel mimics the layout of the manuscript submission form.  It can
 * double as a form to fill out, and as a display for previously submitted
 * forms.
 * 
 * @author Aaron Chen
 * @version 3/6/2014
 */
@SuppressWarnings("serial")
public class ManuscriptSubmissionPanel extends AbstractForm {
  
  /** The text field for the author's name. */
  private JTextField my_tf_author;
  
  /** The text field for the author's email. */
  private JTextField my_tf_email;
  
  /** The text field for the name of the conference the manuscript
   * is/was being submitted to. */
  private JTextField my_tf_conference_name;
  
  /** The text field for the categories of the conference the
   * manuscript is/was being submitted to. */
  private JTextField my_tf_conference_category;
  
  /** The text field for the key words used to aid the system's
   * search engine. */
  private JTextField my_tf_key_words;
  
  /** The text field for the manuscript's title. */
  private JTextField my_tf_manuscript_title;
  
  /** The text area for the manuscript's abstract. */
  private JTextArea my_ta_abstract;
  
  /** The text area for the manuscript's full text. */
  private JTextArea my_ta_full_text;

  
  /**
   * {@inheritDoc}
   */
  @Override
  protected String getFormTitle() {
    return "Manuscript Submission Form";
  }
  
  /**
   * {@inheritDoc}
   */
  @Override
  protected JPanel createFormPanel() {
    final JPanel panel_form = new JPanel();
    panel_form.setLayout(new BoxLayout(panel_form, BoxLayout.Y_AXIS));
    panel_form.setBackground(Standards.COLOR_BACKGROUND);
    panel_form.setBorder(Standards.BORDER_COMPOUND_FORM);
    
    panel_form.add(createColumnedPanel());
    panel_form.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    
    setUpTextFields(panel_form);
    setUpTextAreas(panel_form);
    
    return panel_form;
  }
  
  /**
   * Populates the manuscript submission form with text fields and their
   * respective labels.
   * @param the_panel The panel of the form.
   */
  private void setUpTextFields(final JPanel the_panel) {
    final JPanel panel_key_words = new JPanel();
    panel_key_words.setBackground(Standards.COLOR_BACKGROUND);
    panel_key_words.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_key_words = new JLabel("Key Words");
    panel_key_words.add(lbl_key_words, BorderLayout.CENTER);
    
    my_tf_key_words = new JTextField();
    my_tf_key_words.setToolTipText("Key words help search engines find your manuscript.");
    panel_key_words.add(my_tf_key_words, BorderLayout.SOUTH);
    
    final JPanel panel_manuscript_title = new JPanel();
    panel_manuscript_title.setBackground(Standards.COLOR_BACKGROUND);
    panel_manuscript_title.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_manuscript_title = new JLabel("Manuscript Title");
    panel_manuscript_title.add(lbl_manuscript_title, BorderLayout.CENTER);
    
    my_tf_manuscript_title = new JTextField();
    my_tf_manuscript_title.setToolTipText("The manuscript's full title (max 100 characters).");
    panel_manuscript_title.add(my_tf_manuscript_title, BorderLayout.SOUTH);

    the_panel.add(panel_key_words);
    the_panel.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    the_panel.add(panel_manuscript_title);
    the_panel.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
  }
  
  /**
   * Populates the manuscript submission form with text areas and their
   * respective labels.
   * @param the_panel The panel of the form.
   */
  private void setUpTextAreas(final JPanel the_panel) {
    final JPanel panel_abstract = new JPanel();
    panel_abstract.setBackground(Standards.COLOR_BACKGROUND);
    panel_abstract.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_abstract = new JLabel("Abstract");
    panel_abstract.add(lbl_abstract, BorderLayout.CENTER);
    
    my_ta_abstract = new JTextArea();
    my_ta_abstract.setToolTipText("A short summary of your manuscript.");
    my_ta_abstract.setRows(Standards.TEXT_AREA_MEDIUM_ROWS);
    my_ta_abstract.setWrapStyleWord(true);
    my_ta_abstract.setLineWrap(true);
    
    panel_abstract.add(createScrollPane(my_ta_abstract), BorderLayout.SOUTH);

    
    final JPanel panel_text = new JPanel();
    panel_text.setBackground(Standards.COLOR_BACKGROUND);
    panel_text.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_text = new JLabel("Text");
    panel_text.add(lbl_text, BorderLayout.CENTER);
    
    my_ta_full_text = new JTextArea();
    my_ta_full_text.setToolTipText("The full text of your manuscript.");
    my_ta_full_text.setRows(Standards.TEXT_AREA_LARGE_ROWS);
    my_ta_full_text.setWrapStyleWord(true);
    my_ta_full_text.setLineWrap(true);
    
    panel_text.add(createScrollPane(my_ta_full_text), BorderLayout.SOUTH);
    
    the_panel.add(panel_abstract);
    the_panel.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    the_panel.add(panel_text);
  }
  
  /**
   * Creates the columned portion of the form panel.
   * @return The columned panel.
   */
  private JPanel createColumnedPanel() {
    final JPanel panel_column_split = new JPanel();
    panel_column_split.setBackground(Standards.COLOR_BACKGROUND);
    panel_column_split.setLayout(new BoxLayout(panel_column_split, BoxLayout.X_AXIS));

    panel_column_split.add(createLeftColumnPanel());
    panel_column_split.add(Box.createHorizontalStrut(Standards.STRUT_LENGTH_LARGE));
    panel_column_split.add(createRightColumnPanel());
    
    return panel_column_split;
  }
  
  /**
   * Creates the left column of the columned panel.
   * @return The left column panel.
   */
  private JPanel createLeftColumnPanel() {
    final JPanel panel_left_column = new JPanel();
    panel_left_column.setBackground(Standards.COLOR_BACKGROUND);
    panel_left_column.setLayout(new BoxLayout(panel_left_column, BoxLayout.Y_AXIS));
    
    final JPanel panel_author = new JPanel();
    panel_author.setBackground(Standards.COLOR_BACKGROUND);
    panel_author.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_author = new JLabel("Author");
    
    my_tf_author = new JTextField();
    my_tf_author.setToolTipText("The submitting author's name.");
    my_tf_author.setColumns(Standards.TEXT_BOX_HALF_WIDTH);
    
    final JPanel panel_conference_name = new JPanel();
    panel_conference_name.setBackground(Standards.COLOR_BACKGROUND);
    panel_conference_name.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_conference = new JLabel("Conference");
    
    my_tf_conference_name = new JTextField();
    my_tf_conference_name.setToolTipText("The conference the manuscript "
                                         + "is being submitted to.");
    my_tf_conference_name.setColumns(Standards.TEXT_BOX_HALF_WIDTH);

    panel_left_column.add(panel_author);
    panel_author.add(lbl_author, BorderLayout.CENTER);
    panel_author.add(my_tf_author, BorderLayout.SOUTH);
    panel_left_column.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    panel_left_column.add(panel_conference_name);
    panel_conference_name.add(lbl_conference, BorderLayout.CENTER);
    panel_conference_name.add(my_tf_conference_name, BorderLayout.SOUTH);
    
    return panel_left_column;
  }
  
  /**
   * Creates the right column of the columned panel.
   * @return The right column panel.
   */
  private JPanel createRightColumnPanel() {
    final JPanel panel_right_column = new JPanel();
    panel_right_column.setBackground(Standards.COLOR_BACKGROUND);
    panel_right_column.setLayout(new BoxLayout(panel_right_column, BoxLayout.Y_AXIS));
    
    final JPanel panel_email = new JPanel();
    panel_email.setBackground(Standards.COLOR_BACKGROUND);
    panel_email.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_email = new JLabel("Email");
    
    my_tf_email = new JTextField();
    my_tf_email.setToolTipText("The submitting author's email address.");
    my_tf_email.setColumns(Standards.TEXT_BOX_HALF_WIDTH);
    
    final JPanel panel_conference_category = new JPanel();
    panel_conference_category.setBackground(Standards.COLOR_BACKGROUND);
    panel_conference_category.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_conference_category = new JLabel("Conference Category");
    
    my_tf_conference_category = new JTextField();
    my_tf_conference_category.setToolTipText("The particular conference category that"
                                             + " this manuscript will be submitted under.");
    my_tf_conference_category.setColumns(Standards.TEXT_BOX_HALF_WIDTH);

    panel_right_column.add(panel_email);
    panel_email.add(lbl_email, BorderLayout.CENTER);
    panel_email.add(my_tf_email, BorderLayout.SOUTH);
    panel_right_column.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    panel_right_column.add(panel_conference_category);
    panel_conference_category.add(lbl_conference_category, BorderLayout.CENTER);
    panel_conference_category.add(my_tf_conference_category, BorderLayout.SOUTH);
    
    return panel_right_column;
  }
  
}
